﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="common/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
    	<title>Job搜索</title>
<jsp:include page="common/header.jsp"/>
		<script type="text/javascript">
			function toPage(page) {
				$("input[name=page]").val(page);
				$("form").submit();
				return false;
			}
			$(function(){
				var myCalendar = new dhtmlXCalendarObject(["submitFrom", "submitTo"]);
				myCalendar.setWeekStartDay(7);
				myCalendar.setDateFormat("%Y-%m-%d");
				myCalendar.hideTime();
			});
		</script>
	</head>
	<body>
<jsp:include page="common/body-header.jsp"/>
		<form action="job-search.action" method="post">
		<b>查询条件：</b>
		<table>
			<tr>
				<th>Job Identifier</th>
				<td><input type="text" name="jobIdentifier" value="${jobIdentifier.stringIdentifier}" size="30"></td>
			</tr>
			<tr>
				<th>Job Configuration Identifier</th>
				<td><input type="text" name="confIdentifier" value="${confIdentifier.stringIdentifier}" size="30"></td>
			</tr>
			<tr>
				<th>Job Type</th>
				<td><select name="type">
					<option value="">不限</option>
					<option<c:if test='${type=="cmd"}'> selected="selected"</c:if>>cmd</option>
					<option<c:if test='${type=="compound"}'> selected="selected"</c:if>>compound</option>
					<option<c:if test='${type=="loop"}'> selected="selected"</c:if>>loop</option>
				</select></td>
			</tr>
			<tr>
				<th>Job Status</th>
				<td><select name="status">
					<option value="">不限</option>
				<c:forEach var="s" items="${statusList}">
					<option<c:if test="${s==status}"> selected="selected"</c:if>>${s}</option>
				</c:forEach></select></td>
			</tr>
			<tr>
				<th>Job Succeed</th>
				<td><select name="succeed">
					<option value="">不限</option>
					<option<c:if test='${succeed=="true"}'> selected="selected"</c:if>>true</option>
					<option<c:if test='${succeed=="false"}'> selected="selected"</c:if>>false</option>
				</select></td>
			</tr>
			<tr>
				<th>Job Submitter</th>
				<td><input type="text" name="submitter" value="${submitter}" size="30"></td>
			</tr>
			<tr>
				<th>Job 开始提交日期(yyyy-MM-dd)</th>
				<td><input id="submitFrom" type="text" name="submitFrom" value="${submitFrom}" size="30" readonly="readonly"></td>
			</tr>
			<tr>
				<th>Job 结束提交日期(yyyy-MM-dd)</th>
				<td><input id="submitTo" type="text" name="submitTo" value="${submitTo}" size="30" readonly="readonly"></td>
			</tr>
		</table>
		<input type="submit" value="查询" onclick="toPage(0)">
		<hr>
		<b>搜索结果：</b>
<c:if test="${confIdentifier!=null}">
	<c:set var="conf" value="${ss:getJobConf(jobConfController, confIdentifier)}" />
	<c:set var="singleConf" value="${true}" />
</c:if>

		<table>
<c:choose>
	<c:when test="${singleConf && conf.parameterSize>0}">
			<tr>
				<th rowspan="2">Job Identifier</th>
				<th rowspan="2">Submitter</th>
				<th rowspan="2">SubmitTime</th>
				<th rowspan="2">LaunchTime</th>
				<th rowspan="2">FinishTime</th>
				<th rowspan="2">WaitTime</th>
				<th rowspan="2">RunTime</th>
				<th rowspan="2">TotalTime</th>
				<th rowspan="2">Status</th>
				<th rowspan="2">Result</th>
				<th colspan="${conf.parameterSize}">Parameters</th>
			</tr>
			<tr>
		<c:forEach var="p" items="${conf.parameters}">
				<th>${p.name}</th>
		</c:forEach>
			</tr>
	</c:when>
	<c:otherwise>
			<tr>
				<th>Job Identifier</th>
				<th>Job Configuration Identifier</th>
				<th>Type</th>
				<th>Name</th>
				<th>Description</th>
				<th>Submitter</th>
				<th>SubmitTime</th>
				<th>LaunchTime</th>
				<th>FinishTime</th>
				<th>WaitTime</th>
				<th>RunTime</th>
				<th>TotalTime</th>
				<th>Status</th>
				<th>Result</th>
			</tr>
	</c:otherwise>
</c:choose>
			<c:forEach var="job" items="${jobs}" >
			<tr>
				<td><a href="job-result.action?identifier=${job.identifier.stringIdentifier}">${job.identifier.stringIdentifier}</a></td>
<c:if test="${!singleConf}">
	<c:set var="conf" value="${ss:getJobConf(jobConfController, job.jobConfIdentifier)}" />
				<td><a href="job-conf.action?action=view&identifier=${job.jobConfIdentifier.stringIdentifier}">${job.jobConfIdentifier.stringIdentifier}</a></td>
				<td>${job.type}</td>
				<td>${conf.name}</td>
				<td>${conf.description}</td>
</c:if>
				<td>${job.submitter}</td>
				<td>${ss:dateFormat(job.submitTime)}</td>
				<td>${ss:dateFormat(job.launchTime)}</td>
				<td>${ss:dateFormat(job.finishTime)}</td>
				<td>${ss:timeBetween(job.launchTime, job.submitTime)}</td>
				<td>${ss:timeBetween(job.finishTime, job.launchTime)}</td>
				<td>${ss:timeBetween(job.finishTime, job.submitTime)}</td>
				<td>${job.status}</td>
				<td><c:if test="${ss:isFinished(job.status)}"><c:choose>
					<c:when test="${job.succeed}"><img alt="success" src="images/icons/ok.jpg" title="success"></c:when>
					<c:otherwise><img alt="fail" src="images/icons/error.png" title="fail"></c:otherwise>
				</c:choose></c:if></td>
<c:if test="${singleConf && conf.parameterSize>0}">
	<c:forEach var="p" items="${conf.parameters}">
				<td>${ss:getMapValue(job.parameters, p.name)}</td>
	</c:forEach>
</c:if>
			</tr>
			</c:forEach>
			<tr>
				<td>&nbsp;</td>
				<td colspan="10">
					匹配Job数量：${jobSize}，共 ${pageSize} 页，当前第 ${page+1} 页：
					<c:if test="${page>0}">
						<a href="#" onclick="return toPage(0)">首页</a>
						<a href="#" onclick="return toPage(${page-1})">上一页</a>
					</c:if>
					<c:if test="${page<pageSize-1}">
						<a href="#" onclick="return toPage(${page+1})">下一页</a>
						<a href="#" onclick="return toPage(${pageSize-1})">末页</a>
					</c:if>
					<input type="hidden" name="page" value="${page}">
				</td>
			</tr>
		</table>
		</form>
<jsp:include page="common/body-footer.jsp"/>
	</body>
</html>
